#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
#  
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# (C) COPYRIGHT International Business Machines Corp. 2004 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 
####################################################################
#
#   lsswstatactive command
#
#   Syntax: lsswstatactive [ -d <directory> ]| --help ]
#
#            --help               - Prints this message
#
####################################################################
#
#   Initial version - 02/04/04
#
####################################################################

sub exit_routine {
    
     # remove files from /tmp 
     
     exit $ret; 

} # end exit_routine subroutine

###############################################################################
#
# start main body of code
#
################################################################################
$PRGRM  = "lsswstatactive";
$BIN    = "/opt/hsc/bin"; 
$PARMS = 0;
$d_USED = 0;
#default params
$directory_parm = "/tmp/switchStats/";
		
$USAGE = "Usage: lsswstatactive [-d <directory> ] | --help ]\n";

# First check for existence of parameters
if ($#ARGV ne -1) {
	$PARMS = 1;
}

$i=0;
# Determine if -d was used
foreach $ARGV (@ARGV) {
	if ($ARGV =~ /^\s*-d\S*$/ ) { 
		$d_USED = 1;
        $directory_parm = $ARGV[$i + 1];		
	}
	$i++;
}

# If there are parms, need to validate and parse
if ($PARMS == 1) {
	# Check for --help (usage)
	foreach $ARGV (@ARGV) {
		if ($ARGV =~ /^\s*--help\S*$/ ) { 
			# Help was specified
			print $USAGE;    #USAGE
			if ($#ARGV == 0) {
				$ret = 0;
			}
			else {
				# If help and anything else was specified,
				#      it's an error
				$ret = 1;
			}
			&exit_routine;
		} #end if
	} #end foreach

}

$command = "i_stub_FS switchstats -C activeall ";

$command = $command . "-f 0 -c 0 -p 0 -y 0 -a 0 -o 0 -v 0 -m switchStats -z 0 -x 0 -Y " . $directory_parm;

chop($RC = `$BIN/$command`);

if ($RC==0)
{
    print "Command successful.\n";
    print "Logs available at $directory_parm\n";
}       
if ($RC==50)
{
	print "Cannot connect to FNM Daemon\n";
}
if ($RC==51)
{
	print "One or more frame,cage parameters are invalid\n";
}
if ($RC==52)
{
	print "Device Database not available\n";
}
if ($RC==70)
{
	print "Unsupported Switch Statistics command.\n";
}
if ($RC==71)
{
	print "Invalid frame and cage specified.\n";
}
if ($RC==72)
{
	print "Counter already running on specified frame and cage.\n";
}
if ($RC==73)
{
	print "Warning: Counter already running for one or more switches.\n";
    print "Command successful.\n";
}
if ($RC==74)
{
	print "Counter for specified frame and cage is not running.\n";
}
if ($RC==75)
{
	print "No switch counters running.\n";
}
if ($RC==76)
{
	print "Thread failed to initialize.\n";
}
if ($RC==77)
{
	print "Counter not running for one or more switches.\n";
    print "Command successful.\n";			
}
if ($RC==78)
{
	print "Error opening directory specified.  Check to see if directory exists.\n";
}	

$ret = 0;
$exit_routine;
